package com.yswee.mallnavi.view.food.grid;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import com.yswee.framework.widget.adapterview.MGridView;
import com.yswee.framework.widget.layoutview.ILayoutView;
import com.yswee.mallnavi.R;
import com.yswee.mallnavi.entity.info.InfoEntity;
import com.yswee.mallnavi.view.food.IGridView;

public class GridView extends MGridView<InfoEntity> implements IGridView {
	
	private IGridView.IActionCallback mActionCallback;

	public void setActionCallback(IGridView.IActionCallback c) {
		mActionCallback = c;
	}

	private IGridView.IActionCallback mActionCallbackProxy = new IGridView.IActionCallback() {
		@Override
		public void onInfoClicked(View v, InfoEntity info) {
			if (mActionCallback != null) {
				mActionCallback.onInfoClicked(v, info);
			}
		}
	};
	
	public GridView(Context context) {
		super(context);
	}
	
	public GridView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void initializeGridView() {
		super.initializeGridView();
		setHorizontalScrollBarEnabled(false);
		setVerticalScrollBarEnabled(false);
		int space_h = (int) getResources().getDimension(R.dimen.gridview_h_spacing);
		int space_v = (int) getResources().getDimension(R.dimen.gridview_v_spacing);
		setNumColumns(2);
		setStretchMode(android.widget.GridView.STRETCH_COLUMN_WIDTH);
		setHorizontalSpacing(space_h);
		setVerticalSpacing(space_v);
		setSelector(R.drawable.gridview_selector);
	}

	@Override
	protected boolean enabledLoadNextPage() {
		return false;
	}

	@Override
	protected int getListViewType() {
		return GRIDVIEW_TYPE_VIEW;
	}
	
	@Override
	protected ILayoutView<InfoEntity> getLayoutView(int position, InfoEntity t, int itemViewType) {
		GridItem griditem = new GridItem(mContext);
		griditem.setActionCallback(mActionCallbackProxy);
		return griditem;
	}
	
}